package com.example.demo.controller;

import com.example.demo.model.user.UserVO;
import com.example.demo.model.user.UserCreateModel;
import com.example.demo.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/users")
public class UserController {

    @Autowired
    UserService service;

    @GetMapping()
    public List<UserVO> getAllUser() {
        return service.getAllUser();
    }

    @PostMapping("/create")
    public int create(@RequestBody UserCreateModel model) {
        System.out.println("进入controller");
        int i = service.create(model);
        return i;
    }

    @GetMapping("/by-id")
    public UserVO getUserById(@PathVariable Integer id) {
        System.out.println(id);
        return service.getUserById(id);
    }
}
